Types

Num

23

Text

"Luke"

Bool

true

List

["Joe", "Flora"]

Object

{age: 23}

Code

o=> print ("Hello world")

Type Groups

Tree

Anything that can have its own properties

["Joe", "Flora"]
{age: 23}
o=> print ("Hello world")

Data

Anything that cannot have its own properties

23
"Luke"
true

Array

Anything that has iterable properties

"Luke"
["Joe", "Flora"]
{age: 23}
o=> print ("Hello world")

Sub-Types

Num

Int
Odd
Even
Positive
Negative

Text

UpperCase
LowerCase
Capitalised

List

Num[_]
Text[_]

class Person {}
Person[_]

Type Checking

Is

"Luke".is (Text) == true
"Luke".is (Array) == true
"Luke".is (Thing) == true

23.is (Num) == true
23.is (Num.Odd) == true

class Person {}
var luke = new Person
luke.is (Person) == true

As

"6".as (Num) == 6
23.as (Text) == "23"
"Hi".as (List) == ["H", "i"]	//unimplemented

"Luke".as (Type) == Text
[2, 3].as (Type) == List

class Person {}
var luke = new Person
luke.as (Type) == Person

Extending Types Examples

Multiply

Num.O.multiply = function(num) => {
	return this * num
}

3.multiply(2) == 6

Shout

Text[_].O.shout = function() {
	this.o.forEach.x= text => print (text.as(UpperCase))
}

["Joe", "Flora"].shout()	// "JOE" "FLORA"

Half

Even.O.getHalf = function () {
	return this / 2
}

4.getHalf() == 2

Functions

Rocket Operator

Immediately calls a block of code

x=o=> print ("Hello world")

x=o=> {
	print ("Hello")
	print ("Goodbye")
}

Zero Parameter Function

Creates a function with no parameters

var hello = o=> print ("Hello world")

var greet = o=> {
	print ("Hello")
	print ("Goodbye")
}

Safe Optional Parameter

For an optional parameter that won't cause reference errors

var greet = (name =x){
	if (name.Type == Text) say ("Hello " + name)
	else say ("Hello")
}

Bind Arguments

Binds some arguments to a function

var looper = loop.o(10)

looper (num => {
	print ("Counting to 10")
	print ("I've got up to " + num)
})

Bind This

Binds something to a method

var friends = ["Joe", "Flora"]
var friendLooper = friends.o.forEach
friendLooper (friend => {
	print ("Hello " + friend)
})

Final Argument

Calls some code with an argument

print. x= "Hello world"

names.o.forEach.x= name => {
	print ("Hello " + name)
	print ("Goodbye " + name)
}

loop.o(10).x= num => {
	print ("Counting to 10")
	print ("I've got up to " + num)
}

Debug

Print

print ("Hello world")
	

Test

test (age == 23)
test (2 + 2 == 5, "Something is very wrong!")
	

Match

Compare

Compare something to a template
(better match = lower rating)

Compare(2, 2).type == "exact"
Compare("hi", Text).type == "type"
Compare(3, Text).type == false

Compare([3, 2], [Num, 2]).type == "structure"
Compare(a => a+1, a => {}).type == "structure"
Compare({age: 23}, {age: Num}).type == "structure"

Compare(2, 2).rating < Compare(2, Num).rating

Match

Matches a thing to a pattern

var response = match (input, 
	Num,			"That's a number",
	42,				"That's a specific number",
	[Text, Text],	"That's an array of two strings",
	_,				"It's something else",
)

name.match (
	"Luke",	 o=> print ("It's me!"),
	"Flora", o=> print ("It's you!")
)

Matcher

Creates a function that matches its arguments

var fibonacci = matcher (
	[0],   0,
	[1],   1,
	[Num], n => fibonacci(n-1) + fibonacci(n-2),
)

Tode

Object._.tode

Creates a tode property

function Person (name, surname){
	this.name = name
	this.surname = surname
	this._.fullname.get = o=> this.name + " " + this.surname
}

var luke = new Person("Luke", "Wilson")
luke.fullname == "Luke Wilson"

Maths

Sum

Adds up a list of numbers

[2, 3].sum == 5
	

Product

Multiplies together a list of numbers

[2, 3].product == 6
	

Mean

Finds the average of a list of numbers

[2, 3].mean == 2.5
	

Multiple

15.isMultipleOf (3) == true
	

Factor

3.isFactorOf (15) == true
	

Examples

Convo

var name = ask ("What is your name?")
var age = ask ("How old are you?").Num
say (`Next year you will be ${age+1} years old ${name}`)

Blastoff

[10, to, 0].o.forEach.x= matcher (
	[0], o => print ("Blast off!"),
	[ ], n => print (n),
)

Fibonacci

var fibonacci = matcher (
	[0],   0,
	[1],   1,
	[Num], n => fibonacci(n-1) + fibonacci(n-2),
)

Factorial

var factorial = matcher (
	[0],   1,
	[Num], n => n * factorial(n-1),
)

Fizzbuzz

var fizzbuzz = n => match (
	n.isMultipleOf (15), "Fizzbuzz",
	n.isMultipleOf (5),  "Buzz",
	n.isMultipleOf (3),  "Fizz",
	_, n.as(Text)
)